<?php

namespace App\Admin\Actions\Post;

use App\Models\CompanyJob;
use Encore\Admin\Actions\BatchAction;
use Illuminate\Database\Eloquent\Collection;

class AllJobAgree extends BatchAction
{
    public $name = '批量同意';

    public function handle(Collection $collection)
    {
        foreach ($collection as $model) {
            if (!in_array($model->job_status, [-2, 0])) {
                continue;
            }
            $res = CompanyJob::where('id', $model->id)->update([
                'job_status' => 1
            ]);
            if (!$res) {
                return $this->response()->error('操作失败！')->refresh();
            }
        }

        return $this->response()->success('操作成功')->refresh();
    }

    public function dialog()
    {
        $this->confirm('确定同意吗？');
    }

}